<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dependency Graph Expressions &#8212; cmt  documentation</title>
    <link rel="stylesheet" href="_static/bootstrap-sphinx.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
    <script src="_static/jquery.js"></script>
    <script src="_static/underscore.js"></script>
    <script src="_static/doctools.js"></script>
    <script src="_static/language_data.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Custom Widgets" href="customwidgets.html" />
    <link rel="prev" title="Curve Control Creator" href="rig/control.html" />
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript" src="_static/js/jquery-1.11.0.min.js "></script>
<script type="text/javascript" src="_static/js/jquery-fix.js "></script>
<script type="text/javascript" src="_static/bootstrap-3.3.7/js/bootstrap.min.js "></script>
<script type="text/javascript" src="_static/bootstrap-sphinx.js "></script>

  </head><body>

  <div id="navbar" class="navbar navbar-default navbar-fixed-top">
    <div class="container">
      <div class="navbar-header">
        <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="index.html">
          cmt</a>
        <span class="navbar-text navbar-version pull-left"><b></b></span>
      </div>

        <div class="collapse navbar-collapse nav-collapse">
          <ul class="nav navbar-nav">
            
            
              <li class="dropdown globaltoc-container">
  <a role="button"
     id="dLabelGlobalToc"
     data-toggle="dropdown"
     data-target="#"
     href="index.html">Site <b class="caret"></b></a>
  <ul class="dropdown-menu globaltoc"
      role="menu"
      aria-labelledby="dLabelGlobalToc"><ul class="current">
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation Instructions</a></li>
<li class="toctree-l1"><a class="reference internal" href="rigging.html">Rigging Tools</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Dependency Graph Expressions</a></li>
<li class="toctree-l1"><a class="reference internal" href="customwidgets.html">Custom Widgets</a></li>
</ul>
</ul>
</li>
              
                <li class="dropdown">
  <a role="button"
     id="dLabelLocalToc"
     data-toggle="dropdown"
     data-target="#"
     href="#">Page <b class="caret"></b></a>
  <ul class="dropdown-menu localtoc"
      role="menu"
      aria-labelledby="dLabelLocalToc"><ul>
<li><a class="reference internal" href="#">Dependency Graph Expressions</a><ul>
<li><a class="reference internal" href="#example-usage">Example Usage</a></li>
<li><a class="reference internal" href="#supported-syntax">Supported Syntax</a></li>
<li><a class="reference internal" href="#use-case">Use Case</a></li>
</ul>
</li>
</ul>
</ul>
</li>
              
            
            
              
                
  <li>
    <a href="rig/control.html" title="Previous Chapter: Curve Control Creator"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm hidden-tablet">&laquo; Curve Control Creator</span>
    </a>
  </li>
  <li>
    <a href="customwidgets.html" title="Next Chapter: Custom Widgets"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm hidden-tablet">Custom Widgets &raquo;</span>
    </a>
  </li>
              
            
            
            
            
              <li class="hidden-sm">
<div id="sourcelink">
  <a href="_sources/dge.rst.txt"
     rel="nofollow">Source</a>
</div></li>
            
          </ul>

          
            
<form class="navbar-form navbar-right" action="search.html" method="get">
 <div class="form-group">
  <input type="text" name="q" class="form-control" placeholder="Search" />
 </div>
  <input type="hidden" name="check_keywords" value="yes" />
  <input type="hidden" name="area" value="default" />
</form>
          
        </div>
    </div>
  </div>

<div class="container">
  <div class="row">
    <div class="body col-md-12 content" role="main">
      
  <div class="section" id="module-cmt.dge">
<span id="dependency-graph-expressions"></span><h1>Dependency Graph Expressions<a class="headerlink" href="#module-cmt.dge" title="Permalink to this headline">¶</a></h1>
<p>Allows the creation of node networks through equation strings.</p>
<p>Dependency Graph Expressions (dge) is a convenience API used to simplify the creation
of Maya DG node networks.  Rather than scripting out many createNode, get/setAttr,
connectAttr commands, you can specify a string equation.</p>
<p>No compiled plug-ins are used.  All created nodes are vanilla Maya nodes.  Each created
node has notes added to it to describe its place in the equation</p>
<div class="section" id="example-usage">
<h2>Example Usage<a class="headerlink" href="#example-usage" title="Permalink to this headline">¶</a></h2>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cmt.dge</span> <span class="kn">import</span> <span class="n">dge</span>

<span class="c1"># Create a simple mathematical graph</span>
<span class="n">loc</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">spaceLocator</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">dge</span><span class="p">(</span><span class="s2">&quot;(x+3)*(2+x)&quot;</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.tx&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">loc</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.ty&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">loc</span><span class="p">))</span>

<span class="c1"># Use assignment operator to auto-connect</span>
<span class="n">loc</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">spaceLocator</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">dge</span><span class="p">(</span><span class="s2">&quot;y=x^2&quot;</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.tx&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">loc</span><span class="p">),</span> <span class="n">y</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.ty&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">loc</span><span class="p">))</span>

<span class="c1"># More complex example with ternary operator and functions</span>
<span class="n">soft_ik_percentage</span> <span class="o">=</span> <span class="n">dge</span><span class="p">(</span>
    <span class="s2">&quot;x &gt; (1.0 - softIk)&quot;</span>
    <span class="s2">&quot;? (1.0 - softIk) + softIk * (1.0 - exp(-(x - (1.0 - softIk)) / softIk)) &quot;</span>
    <span class="s2">&quot;: x&quot;</span><span class="p">,</span>
    <span class="n">x</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.outputX&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">stretch_scale_mdn</span><span class="p">)</span>
    <span class="n">softIk</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.softIk&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ik_control</span><span class="p">),</span>
<span class="p">)</span>

<span class="c1"># Put the created nodes in a container</span>
<span class="n">soft_ik_percentage</span> <span class="o">=</span> <span class="n">dge</span><span class="p">(</span>
    <span class="s2">&quot;x &gt; (1.0 - softIk)&quot;</span>
    <span class="s2">&quot;? (1.0 - softIk) + softIk * (1.0 - exp(-(x - (1.0 - softIk)) / softIk)) &quot;</span>
    <span class="s2">&quot;: x&quot;</span><span class="p">,</span>
    <span class="n">container</span><span class="o">=</span><span class="s2">&quot;softik_equation&quot;</span><span class="p">,</span>
    <span class="n">x</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.outputX&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">stretch_scale_mdn</span><span class="p">)</span>
    <span class="n">softIk</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.softIk&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ik_control</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="supported-syntax">
<h2>Supported Syntax<a class="headerlink" href="#supported-syntax" title="Permalink to this headline">¶</a></h2>
<p>Operators:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>+  # addition
-  # subtraction
*  # multiplication
/  # division
^  # power,
?: # ternary
</pre></div>
</div>
<p>Functions:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">abs</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">clamp</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="nb">min</span><span class="p">,</span> <span class="nb">max</span><span class="p">)</span>
<span class="n">lerp</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span>
<span class="nb">min</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="nb">max</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">sqrt</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">tan</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">acos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">asin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">atan</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="n">distance</span><span class="p">(</span><span class="n">node1</span><span class="p">,</span> <span class="n">node2</span><span class="p">)</span>
</pre></div>
</div>
<p>Constants:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">PI</span>
<span class="n">E</span>
</pre></div>
</div>
</div>
<div class="section" id="use-case">
<h2>Use Case<a class="headerlink" href="#use-case" title="Permalink to this headline">¶</a></h2>
<p>Before:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># (1.0 - softik)</span>
<span class="n">one_minus</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">createNode</span><span class="p">(</span>
    <span class="s2">&quot;plusMinusAverage&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_one_minus_softik&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.operation&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1D[0]&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus</span><span class="p">),</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="n">softik</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1D[1]&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus</span><span class="p">))</span>

<span class="c1"># x - (1.0 - softik)</span>
<span class="n">x_minus</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">createNode</span><span class="p">(</span>
    <span class="s2">&quot;plusMinusAverage&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_x_minus_one_minus_softik&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.operation&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">x_minus</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">percent_rest_distance</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1D[0]&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">x_minus</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span>
    <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.output1D&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1D[1]&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">x_minus</span><span class="p">)</span>
<span class="p">)</span>

<span class="c1"># -(x - (1.0 - softik))</span>
<span class="n">negate</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">createNode</span><span class="p">(</span>
    <span class="s2">&quot;multDoubleLinear&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_softik_negate&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">negate</span><span class="p">),</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.output1D&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">x_minus</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input2&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">negate</span><span class="p">))</span>

<span class="c1"># -(x - (1.0 - softik)) / softik</span>
<span class="n">divide</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">createNode</span><span class="p">(</span>
    <span class="s2">&quot;multiplyDivide&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_softik_divide&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.operation&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">divide</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>  <span class="c1"># divide</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.output&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">negate</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1X&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">divide</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="n">softik</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input2X&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">divide</span><span class="p">))</span>

<span class="c1"># exp(-(x - (1.0 - softIk)) / softIk)</span>
<span class="n">exp</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">createNode</span><span class="p">(</span><span class="s2">&quot;multiplyDivide&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_softik_exp&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.operation&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">exp</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>  <span class="c1"># pow</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1X&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">exp</span><span class="p">),</span> <span class="mf">2.71828</span><span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.outputX&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">divide</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input2X&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">exp</span><span class="p">))</span>

<span class="c1"># 1.0 - exp(-(x - (1.0 - softIk)) / softIk)</span>
<span class="n">one_minus_exp</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">createNode</span><span class="p">(</span>
    <span class="s2">&quot;plusMinusAverage&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_one_minus_exp&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.operation&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus_exp</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1D[0]&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus_exp</span><span class="p">),</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span>
    <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.outputX&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">exp</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1D[1]&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus_exp</span><span class="p">)</span>
<span class="p">)</span>

<span class="c1"># softik * (1.0 - exp(-(x - (1.0 - softIk)) / softIk))</span>
<span class="n">mdl</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">createNode</span><span class="p">(</span>
    <span class="s2">&quot;multDoubleLinear&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_softik_mdl&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="n">softik</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mdl</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.output1D&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus_exp</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input2&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mdl</span><span class="p">))</span>

<span class="c1"># (1.0 - softik) + softik * (1.0 - exp(-(x - (1.0 - softIk)) / softIk))</span>
<span class="n">adl</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">createNode</span><span class="p">(</span><span class="s2">&quot;addDoubleLinear&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_softik_adl&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.output1D&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input1&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">adl</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.output&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">mdl</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.input2&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">adl</span><span class="p">))</span>
<span class="c1"># Now output of adl is the % of the rest distance the ik handle should be from</span>
<span class="c1"># the start joint</span>

<span class="c1"># Only adjust the ik handle if it is less than the soft percentage threshold</span>
<span class="n">cnd</span> <span class="o">=</span> <span class="n">cmds</span><span class="o">.</span><span class="n">createNode</span><span class="p">(</span>
    <span class="s2">&quot;condition&quot;</span><span class="p">,</span>
    <span class="n">name</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_current_length_greater_than_soft_length&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">),</span>
<span class="p">)</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">setAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.operation&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cnd</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>  <span class="c1"># greater than</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">percent_rest_distance</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.firstTerm&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cnd</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.output1D&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">one_minus</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.secondTerm&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cnd</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.output&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">adl</span><span class="p">),</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.colorIfTrueR&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cnd</span><span class="p">))</span>
<span class="n">cmds</span><span class="o">.</span><span class="n">connectAttr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">percent_rest_distance</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.colorIfFalseR&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cnd</span><span class="p">))</span>

<span class="n">softik_percentage</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">.outColorR&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">cnd</span><span class="p">)</span>
</pre></div>
</div>
<p>After:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">soft_ik_percentage</span> <span class="o">=</span> <span class="n">dge</span><span class="p">(</span>
    <span class="s2">&quot;x &gt; (1.0 - softIk)&quot;</span>
    <span class="s2">&quot;? (1.0 - softIk) + softIk * (1.0 - exp(-(x - (1.0 - softIk)) / softIk)) &quot;</span>
    <span class="s2">&quot;: x&quot;</span><span class="p">,</span>
    <span class="n">container</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_softik&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">),</span>
    <span class="n">x</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">percent_rest_distance</span><span class="p">,</span>
    <span class="n">softIk</span><span class="o">=</span><span class="n">softik</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
</div>


    </div>
      
  </div>
</div>
<footer class="footer">
  <div class="container">
    <p class="pull-right">
      <a href="#">Back to top</a>
      
    </p>
    <p>
        &copy; Copyright 2018, Chad Vernon.<br/>
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 3.1.2.<br/>
    </p>
  </div>
</footer>
  </body>
</html>